﻿using System;
using System.Collections.Generic; 
using System.ComponentModel;
using System.Linq;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;
 

namespace NTTDATA.BEENChina.ResultCertification.Checker.Select
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityS0400", Name = "选择项目公式验证", CategoryType = EnumCategoryType.选择, Model = true)]
    public class VerfityS0400 : VerfityOneResult
    {
        private CustomCollection<ExpressionCondition> _conditions = new CustomCollection<ExpressionCondition>()
                                                                        {
                                                                            Description = "表达式条件"
                                                                        };

        [TypeConverter(typeof(CustomCollectionConverter<ExpressionCondition>))]
        [RefreshProperties(RefreshProperties.All)]
        public CustomCollection<ExpressionCondition> Conditions 
        {
            get { return _conditions; }
            set { _conditions = value ;}
        } 
  
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            try
            {
                if (entryCommon == "30" || entryCommon == "20")
                {
                    return false; 
                }

                var dataResult = result.Select(t => t.Select(tt =>
                                                                 {
                                                                     var splitReuslt =
                                                                         new Split.SplitEntryResult(
                                                                             ChildImageObject.CategorySetting.DataFormat,
                                                                             tt);
                                                                     return splitReuslt.GetSelect();
                                                                 }).ToList()).ToList();
               //.Where(t => t.All(CheckResult))

               return new VerfityExpression().CheckStringExpression(dataResult , _conditions);
            }
            catch (ExpressionErrorException exp)
            {
                throw exp;
            }
            catch (CellEmptyException exp)
            {
                return false;
            }
            catch (Exception exp)
            {
                return false;
            }
        }


        private bool CheckResult( string  result )
        {
            if (EmptyResultCount(result).Equals(0))
                return true;

            return false;
        }

    }


   
   


}